﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace DlrBasic.Runtime
{
    /// <summary>
    /// BASIC built in math and logical operators such as power,
    /// division, logical or/and/xor, etc.
    /// </summary>
    public static class DlrBasicMath
    {
        public static double PowerInt(short x, short y)
        {
            return Math.Pow(x, y);
        }

        public static double PowerSingle(float x, float y)
        {
            return Math.Pow(x, y);
        }

        public static double PowerDouble(double x, double y)
        {
            return Math.Pow(x, y);
        }

        public static short MultiplyInt(short x, short y)
        {
            return (short)(x * y);
        }

        public static float MultiplySingle(float x, float y)
        {
            return x * y;
        }

        public static double MultiplyDouble(double x, double y)
        {
            return x * y;
        }

        public static float DivisionInt(short x, short y)
        {
            return (float)x / y;
        }

        public static float DivisionSingle(float x, float y)
        {
            return x / y;
        }

        public static double DivisionDouble(double x, double y)
        {
            return x / y;
        }

        public static short IntDivisionInt(short x, short y)
        {
            return (short)(x / y);
        }

        public static short ReminderInt(short x, short y)
        {
            return (short)(x % y);
        }

        public static float AddInt(short x, short y)
        {
            return x + y;
        }

        public static float AddSingle(float x, float y)
        {
            return x + y;
        }

        public static double AddDouble(double x, double y)
        {
            return x + y;
        }

        public static string AddString(string x, string y)
        {
            // if (x == "+K+" || y == "+K+") System.Diagnostics.Debugger.Break();

            return String.Concat(x, y);
        }

        public static short SubtractInt(short x, short y)
        {
            return (short)(x - y);
        }

        public static float SubtractSingle(float x, float y)
        {
            return x - y;
        }

        public static double SubtractDouble(double x, double y)
        {
            return x - y;
        }

        public static short NegateInt(short x)
        {
            return (short)(-x);
        }

        public static float NegateSingle(float x)
        {
            return -x;
        }

        public static double NegateDouble(double x)
        {
            return -x;
        }

        public static short NotInt(short x)
        {
            return (short)(~x);
        }

        public static short AndInt(short x, short y)
        {
            return (short)(x & y);
        }

        public static short OrInt(short x, short y)
        {
            return (short)(x | y);
        }

        public static short XorInt(short x, short y)
        {
            return (short)(x ^ y);
        }

        public static short EqvInt(short x, short y)
        {
            return (short)(~(x ^ y));
        }

        public static short ImpInt(short x, short y)
        {
            return (short)((~(ushort)x) | (ushort)y);
        }
    }
}
